
package hr.infomare.instalacija.test;

import java.awt.Color;

import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

/**
 *
 * @author damirl
 */
public class FormJTextArea extends java.awt.Frame {

    /** Creates new form FormJTextArea */
    public FormJTextArea() {
        initComponents();
        pack();
        setLocationRelativeTo(null);
        inicijalizacija();
    }

    private void inicijalizacija() {

        SimpleAttributeSet attrs = new SimpleAttributeSet();
        StyleConstants.setForeground(attrs, Color.blue);

        SimpleAttributeSet attrsRed = new SimpleAttributeSet();
        StyleConstants.setForeground(attrsRed, Color.red);

        jTextPane1.setText("<font color='blue'><b><i>Tekst...</b></font> <==tekst boje==> <font color='red'><b> Tekst opet druge boje</b></font> \n");
        Document doc = jTextPane1.getDocument();
        int pozicija = 0;
        for (int i = 0; i < 10; i++) {
            pozicija = doc.getLength();
            try {
                jTextPane1.getStyledDocument().insertString(pozicija,
                                                            "<font color='blue'><b><i>Tekst...</b></font> <==tekst boje==> <font color='red'><b> Tekst opet druge boje</b></font>\n",
                                                            i % 2 == 0 ? attrs : attrsRed);
            } catch (BadLocationException e) {
            }

        }
        jTextPane1.repaint();
        jTextPane1.revalidate();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();

        setPreferredSize(new java.awt.Dimension(780, 512));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        jTextPane1.setContentType("text/html"); // NOI18N
        jTextPane1.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jScrollPane1.setViewportView(jTextPane1);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);

        pack();
    }//GEN-END:initComponents

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
        System.exit(0);
    }//GEN-LAST:event_exitForm

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormJTextArea().setVisible(true);
            }
        });
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration//GEN-END:variables

}
